/* name: guess
 * author: 5ab
 * created at: 2024-05-30
 */
#include <bits/stdc++.h>
using namespace std;

#define all(x) (x).begin(), (x).end()
#define ssz(x) (int((x).size()))

auto chmax = [](auto& x, auto y) { if (x < y) x = y; };
auto chmin = [](auto& x, auto y) { if (y < x) x = y; };

using ll = long long;
const int N = 1e7;

int a[N], b[N];

signed main()
{
	freopen("guess.in", "r", stdin);
	freopen("guess.out", "w", stdout);
	
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	
	int T, n, sa, ax, bx, cx, mod;
	
	cin >> T;
	while (T--)
	{
		cin >> n >> sa >> ax >> bx >> cx >> mod;
		for (int i = 0; i < n; i++)
		{
			sa = a[i] = ((1ll * ax * sa + bx) % mod * sa + cx) % mod + 1;
			// cerr << a[i] << " \n"[i == n - 1];
		}
		int m = 0;
		sort(a, a + n);
		for (int i = 0, j = 0; i < n; i = j)
		{
			for (j = i; j < n && a[i] == a[j]; j++);
			b[m++] = (j - i != 1);
		}
		
		for (int i = 0; i < m; i++)
			cerr << b[i] << " \n"[i == m - 1];
		
		double l = 0, r = 1;
		auto chk = [&](double p) -> bool
		{
			double mns = 114;
			for (int i = 0; i < m; i++)
			{
				double cp = 1 - b[i] * p;
				if (mns + cp < p * 2)
					return 0;
				mns = cp - max(0., p * 2 - mns);
			}
			return 1;
		};
		for (int _ = 0; _ < 15; _++)
		{
			double mid = (l + r) / 2;
			if (chk(mid))
				l = mid;
			else
				r = mid;
		}
		cout << fixed << setprecision(5) << l << " 0\n";
	}
	
	return 0;
}
// started coding at: 05-30 08:52:15